package org.nViron.nvOrganic;

//~--- non-JDK imports --------------------------------------------------------

import org.nViron.nvOrganism.nvStateMgr;
import org.nViron.nvRender.nvVec3;

import traer.physics.Particle;
import traer.physics.Vector3D;

/**
 * A kinetic is a moveable point within a tissue structure. In between two kinetics always is a joint
 * @author Roland Haring <p>
 * <script type="text/javascript" src="http://www.ohloh.net/p/376434/widgets/project_basic_stats.js"></script>
 */
public abstract class nvKinetic extends nvTissue {
    protected float    c1;    // distance to parent
    protected float    c2;    // distance to siblings
    protected nvJoint  connectingJoint;
    protected int      level;
    protected Particle particle;

    public nvKinetic(nvOrganic organic, nvJoint parent) {
        super(organic, parent);
        connectingJoint = parent;

        if (connectingJoint != null) {
            level = connectingJoint.getSource().getLevel() + 1;
        }
    }

    public float getC1() {
        return c1;
    }

    public float getC2() {
        return c2;
    }

    public nvJoint getConnectingJoint() {
        return connectingJoint;
    }

    public abstract nvVec3 getCurrentRenderPos();

    public abstract Vector3D getInitialVelocity();

    public int getLevel() {
        return level;
    }

    protected abstract int getNumChildren();

    public Particle getParticle() {
        return particle;
    }

    public boolean hasParticle() {
        return particle != null;
    }

    public void setC1(float val) {
        c1 = val;
    }

    public void setC2(float val) {
        c2 = val;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    @Override
    public void update(float timeStep) {
        super.update(timeStep);

        if (getState() == nvStateMgr.DEAD) {
            getOrganic().removeParticle(particle);
        }
    }
}



